package com.easy.service.impl;

import com.easy.bean.Rooms;
import com.easy.dao.IRoomsDao;
import com.easy.service.IRooms;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class RoomsImpl implements IRooms {
    @Autowired
    IRoomsDao dao;

    public Rooms getRooms(int id){
        return dao.getRooms(id);
    }

    //删除
    @Override
    public int delRooms(int id){
        int count=dao.delRooms(id);
        return count;
    }

    //修改
    public int editRooms(Rooms rooms){
        int count=dao.editRooms(rooms);
        return count;
    }

    @Override
    public int editRooms_check(Rooms rooms) {
        int count=dao.editRooms_check(rooms);
        return count;
    }

    @Override
    public List<Rooms> getSearchRooms(Rooms rooms, Page page) {
        return dao.getSearchRooms(rooms,page);
    }

    @Override
    public List<Rooms> findfreeRooms(Rooms rooms) {
        return dao.findfreeRooms(rooms);
    }

    public int getCount(Rooms rooms){
        return dao.getCount(rooms);
    }


    //图表
    @Override
    public List<Rooms> getAllRooms() {
        return dao.getAllRooms();
    }

    @Override
    public Map<String, Integer> getRoomStatusCounts(Rooms rooms) {
        List<Rooms> allRooms = dao.getAllRooms();

        Map<String, Integer> statusCounts = new HashMap<>();
        for (Rooms room : allRooms) {
            String status = room.getStatus();
            statusCounts.put(status, statusCounts.getOrDefault(status, 0) + 1);
        }

        return statusCounts;
    }
}
